/*     */ package com.zimbra.cs.filter.jsieve;
/*     */ 
/*     */ import com.google.common.base.Splitter;
/*     */ import com.google.common.collect.ImmutableSet;
/*     */ import com.zimbra.common.mime.InternetAddress;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.filter.ZimbraMailAdapter;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.util.AccountUtil;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ import org.apache.jsieve.Arguments;
/*     */ import org.apache.jsieve.SieveContext;
/*     */ import org.apache.jsieve.exception.SieveException;
/*     */ import org.apache.jsieve.mail.MailAdapter;
/*     */ import org.apache.jsieve.tests.AbstractTest;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class BulkTest
/*     */   extends AbstractTest
/*     */ {
/*  43 */   private static final Set<String> HEADERS = ImmutableSet.of("X-ANTIABUSE", "X-REPORT-ABUSE", "X-ABUSE-REPORTS-TO", "X-MAIL_ABUSE_INQUIRES", "X-JOB", "UNSUBSCRIBE", new String[] { "REMOVEEMAIL" });
/*     */   private static final String LIST_UNSUBSCRIBE = "LIST-UNSUBSCRIBE";
/*     */   private static final String PRECEDENCE = "PRECEDENCE";
/*     */   private static final String X_PROOFPOINT_SPAM_DETAILS = "X-PROOFPOINT-SPAM-DETAILS";
/*     */   private static final String AUTO_SUBMITTED = "Auto-Submitted";
/*     */   private static final String ZIMBRA_OOO_AUTO_REPLY = "auto-replied (zimbra; vacation)";
/*     */   
/*     */   protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx)
/*     */     throws SieveException
/*     */   {
/*  53 */     if (!(mail instanceof ZimbraMailAdapter)) {
/*  54 */       return false;
/*     */     }
/*  56 */     ZimbraMailAdapter adapter = (ZimbraMailAdapter)mail;
/*  57 */     for (String name : adapter.getHeaderNames()) {
/*  58 */       name = name.toUpperCase();
/*  59 */       if (HEADERS.contains(name))
/*  60 */         return true;
/*  61 */       if ("LIST-UNSUBSCRIBE".equals(name))
/*     */       {
/*  63 */         List<InternetAddress> addrs = new ArrayList();
/*  64 */         for (String to : mail.getHeader("To")) {
/*  65 */           addrs.addAll(InternetAddress.parseHeader(to));
/*     */         }
/*     */         try {
/*  68 */           me = AccountUtil.getEmailAddresses(adapter.getMailbox().getAccount());
/*  69 */           for (InternetAddress addr : addrs) {
/*  70 */             if (me.contains(addr.getAddress().toLowerCase()))
/*  71 */               return true;
/*     */           }
/*     */         } catch (ServiceException e) {
/*     */           Set<String> me;
/*  75 */           ZimbraLog.filter.error("Failed to lookup my addresses", e);
/*     */         }
/*  77 */       } else if ("PRECEDENCE".equals(name)) {
/*  78 */         for (String precedence : adapter.getHeader("PRECEDENCE")) {
/*  79 */           if ("bulk".equalsIgnoreCase(precedence)) {
/*  80 */             boolean zimbraOOONotif = false;
/*  81 */             for (String autoSubmitted : mail.getHeader("Auto-Submitted")) {
/*  82 */               if ("auto-replied (zimbra; vacation)".equals(autoSubmitted)) {
/*  83 */                 zimbraOOONotif = true;
/*  84 */                 break;
/*     */               }
/*     */             }
/*  87 */             if (!zimbraOOONotif)
/*  88 */               return true;
/*     */           }
/*     */         }
/*     */       } else {
/*  92 */         if (name.contains("CAMPAIGN"))
/*  93 */           return true;
/*  94 */         if (name.equals("X-PROOFPOINT-SPAM-DETAILS")) {
/*  95 */           for (String value : adapter.getHeader("X-PROOFPOINT-SPAM-DETAILS")) {
/*  96 */             for (String field : Splitter.on(' ').split(value)) {
/*  97 */               if (field.startsWith("bulkscore=")) {
/*  98 */                 String[] pair = field.split("=", 2);
/*     */                 try {
/* 100 */                   if ((pair.length == 2) && (Integer.parseInt(pair[1]) >= 50)) {
/* 101 */                     return true;
/*     */                   }
/*     */                 }
/*     */                 catch (NumberFormatException ignore) {}
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 111 */     return false;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/filter/jsieve/BulkTest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */